package com.ptt.sqm.component;

import java.util.List;

import com.ptt.sqmonmobile.R;

import android.content.Context;
import android.database.DataSetObserver;
import android.graphics.Bitmap;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class ImageAdapter extends PagerAdapter {
	Context context;
	private LayoutInflater inflater;
	private List<Bitmap> bitmaps;

	public ImageAdapter(Context context, List bitmaps) {
		this.context = context;
		this.bitmaps = bitmaps;
	}

	@Override
	public int getCount() {
		return bitmaps.size();
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == ((RelativeLayout) object);
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		ImageView imgDisplay;
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View viewLayout = inflater.inflate(R.layout.image_show, container, false);

		imgDisplay = (ImageView) viewLayout.findViewById(R.id.snapshot);
		imgDisplay.setImageBitmap(bitmaps.get(position));

		((ViewPager) container).addView(viewLayout);
		return viewLayout;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		((ViewPager) container).removeView((RelativeLayout) object);
	}

	@Override
	public void unregisterDataSetObserver(DataSetObserver observer) {
		// TODO Auto-generated method stub
		super.unregisterDataSetObserver(observer);
	}
}
